var fso = new ActiveXObject("Scripting.FileSystemObject");
function alert(txt)
{
	WScript.Echo(txt); 
}

function trim(str)
{
try
{
return str.replace(/^\s*|\s*$/g,"");
}
catch(e)
{
return str;
}
}
function readAllLine(fn)
{
	var f=fso.OpenTextFile(fn, 1);
	var r=[];
	while(!f.AtEndOfStream)
	{
		r.push(f.ReadLine());
	}
	f.Close();
	return r;	
}

function readFile(fn)
{
	if(!fso.FileExists(fn)) return "";
	var f=fso.OpenTextFile(fn, 1);
	return f.ReadAll();
	
}
function writeFile(fn,txt)
{
	var f=fso.OpenTextFile(fn, 2,true);
	f.Write(txt);
	f.Close();
}
var htmlHead=readFile("head.html");
var htmlFoot=readFile("foot.html");

function ReadGroup()
{
	var groupNames=readAllLine("..\\groups.txt");
	//alert(groupText);
//	var groupNames = groupText.split("\r\n");
	for(var i=0;i<groupNames.length;i++)
	{
		groupNames[i]=groupNames[i].replace("\0","");
	}
	for(var i=0;i<groupNames.length;i++)
	{
		//groupNames[i]=groupNames[i].replace("\0","");
		//alert(name+"*");
		createHtml(groupNames,i);
	}	
}
function createHtml(groupNames,index)
{
	var gName=groupNames[index];
	var htmlfn=pinyin.go(gName)+".html";
	var groupHtml=[];
	groupHtml.push('<div class="navPanel"><div class="innerNavPanel"><div class="buttons" id="navMenu">');
	for(var i=0;i<groupNames.length;i++)
	{
		var bqFn=pinyin.go(groupNames[i])+".html";
		var classNm='';
		if(i==index) classNm='class="buttons-active"';
		groupHtml.push('<a href="'+bqFn+'" '+classNm+'>'+groupNames[i]+'</a>');
	}
	groupHtml.push("</div></div></div>");
	
	var imgHtml=[];
	imgHtml.push('<div class="shadowStrip">&nbsp;</div>');
	imgHtml.push('<div class="contentWrapper">');
	imgHtml.push('<div class="contentBlock">');
	imgHtml.push('<div class="contentText">');
	imgHtml.push('<p>');

	
	var urls=readAllLine("..\\"+gName+"\\list.txt");
	var length=urls.length;
	for(var i=0;i<length;i++)
	{
		var url=urls[i];
		if(i==length-1) url=url.replace("\0","");
		alert(url);
		var titlefn=encodeURIComponent(url)+".txt";
		var title=readFile("..\\"+gName+"\\"+titlefn);
		if(title) title=' title="'+title+'"';
		else title="";
		imgHtml.push('<img src="'+url+'" '+title+' class="cople" />');
	}

imgHtml.push('</p>');
imgHtml.push('</div>');
imgHtml.push('</div>');
imgHtml.push('</div>');

	alert(gName+"-------------");
	var fullHtml=htmlHead+groupHtml.join("\n")+imgHtml.join("\n")+htmlFoot;
	writeFile("html\\"+htmlfn,fullHtml);
}


ReadGroup();